package com.jxpanda.spring.module.auth.core.authentication.strategy;

import com.jxpanda.spring.module.auth.core.authentication.manager.CollaborativeReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.authentication.manager.UsernamePasswordRepositoryReactiveAuthenticationManager;
import com.jxpanda.spring.module.auth.core.user.OAuth2ReactiveUserDetailsRepository;
import com.jxpanda.spring.module.auth.endpoint.GrantType;
import reactor.core.publisher.Flux;

public class UsernamePasswordCollaborativeReactiveAuthenticationStrategy extends AbstractCollaborativeReactiveAuthenticationStrategy {

    private final UsernamePasswordRepositoryReactiveAuthenticationManager usernamePasswordRepositoryReactiveAuthenticationManager;

    public UsernamePasswordCollaborativeReactiveAuthenticationStrategy(OAuth2ReactiveUserDetailsRepository oAuth2ReactiveUserDetailsRepository) {
        super(oAuth2ReactiveUserDetailsRepository);
        this.usernamePasswordRepositoryReactiveAuthenticationManager = new UsernamePasswordRepositoryReactiveAuthenticationManager(oAuth2ReactiveUserDetailsRepository);
    }

    @Override
    public boolean isSupport(String grantType) {
        return GrantType.PASSWORD.getValue().equals(grantType);
    }

    @Override
    protected Flux<CollaborativeReactiveAuthenticationManager> getAuthenticationChain() {
        return Flux.just(usernamePasswordRepositoryReactiveAuthenticationManager);
    }

}
